package com.xszx.knowledge.service.impl;

import com.xszx.knowledge.entity.Ebook;
import com.xszx.knowledge.mapper.EbookMapper;
import com.xszx.knowledge.service.EbookService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xszx.knowledge.util.SnowFlake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * <p>
 * 电子书 服务实现类
 * </p>
 *
 * @author wencai
 * @since 2023/04/20 10:48
 */
@Service
public class EbookServiceImpl extends ServiceImpl<EbookMapper, Ebook> implements EbookService {
    @Resource
    private SnowFlake snowFlake;
    @Resource
    private EbookMapper ebookMapper;
    @Override
    public boolean saveOrUpdate(Ebook entity) {
        if(!ObjectUtils.isEmpty(entity) && entity.getId() != null){
           return updateById(entity);
        }else{
            entity.setId(snowFlake.nextId());
            return save(entity);
        }
    }

    @Override
    public void updateEbook() {
        ebookMapper.updateEbook();
    }
}
